import { DressUpServerDataMgr } from "./data/DressUpServerDataMgr";
import { DressUpDataParse } from "./DressUpDataParse";
import { MLotteryClothePage } from "./MLotteryClothePage";

export class MDressUpTabDataMgr{

    private _dressDatas:any[];
    private _tabDatas:any[];

    private _isOpen:boolean;
    
    init(tabDatas:any[]){
        this._tabDatas = tabDatas;
    }

    getDefaultDatas(dressData:any){
        return this.getDressDatas(dressData, this.isOpen);
    }

    getDressDatas(dressData:any, isOpen:boolean):any[]{
        this.isOpen = isOpen;
        if(isOpen){
            let istest = true;
            let ids:any[] = [];
            let id = dressData.preform_id;
            let dressUpData = DressUpServerDataMgr.Ins.getDressUpDataById(id);
            if(dressUpData && dressUpData.preform_attribute_desc){
                istest = false;
                ids = dressUpData.preform_attribute_desc.split("-");
            }
            if(istest){
                console.warn("没有配置抽奖套装的妆容数据--->", dressData);
            }
            let dressUps:any = MLotteryClothePage.Ins.dataMgr.getLuckyBoxDressList(ids,istest);//TODO 缺少数据--->
            this._dressDatas = dressUps;
            let idx = this._tabDatas.indexOf(dressData);
            if(idx >=0 ){
                let element;
                for (let index = 0; index < dressUps.length; index++) {
                    element = dressUps[index];
                    element.isfacedressUp = true;
                    this._tabDatas.splice(idx+index+1,0,element);
                }
            }
        }else{
            if(this._dressDatas){
                this._dressDatas.forEach(value=>{
                    let idx = this._tabDatas.indexOf(value);
                    idx >= 0 && this._tabDatas.splice(idx, 1);
                });
            }
        }
        return this._tabDatas;
    }

    public get isOpen(){
        return this._isOpen;
    }

    public set isOpen(value:boolean){
        this._isOpen = value;
    }

    close(){
        this.isOpen = false;
        this._dressDatas = null;
        this._tabDatas = null;
    }
}